﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace YiLe.UI
{
    public partial class DataControl : UserControl
    {
        public virtual Size FullSize
        {
            get { return this.Size; }
        }

        private YiLeSystemData mDataSource;
        public YiLeSystemData DataSource
        {
            get { return mDataSource; }
            set
            {
                if (mDataSource != value)
                {
                    mDataSource = value;
                    OnDataSourceChanged();
                }
            }
        }


        protected virtual void OnDataSourceChanged()
        {
        }

        private bool mAllowEidt = true;
        public bool AllowEidt
        {
            get { return mAllowEidt; }
            set
            {
                if (mAllowEidt != value)
                {
                    mAllowEidt = value;
                    OnAllowEditChanged();
                }
            }
        }


        protected virtual void OnAllowEditChanged()
        {
        }

        protected void AddBinding(Control control, string propertyName, string dataMember)
        {
            control.DataBindings.Clear();
            if (mDataSource == null)
            {
                control.Enabled = false;
            }
            else
            {
                control.DataBindings.Add(propertyName, mDataSource, dataMember);
            }
        }

        private bool mIsAddNew;
        public bool IsAddNew
        {
            get { return mIsAddNew; }
            set
            {
                if (mIsAddNew != value)
                {
                    mIsAddNew = true;
                    OnIsAddNewChanged();
                }
            }
        }

        protected virtual void OnIsAddNewChanged()
        {
        }

        private bool mUseTabBackground;
        public bool UseTabBackground
        {
            get
            {
                return mUseTabBackground;
            }
            set
            {
                if (mUseTabBackground != value)
                {
                    mUseTabBackground = value;
                    this.OnUseTabBackgroundChanged();
                }
            }
        }

        private bool mAllowEdit = true;
        public bool AllowEdit
        {
            get
            {
                return mAllowEdit;
            }
            set
            {
                if (mAllowEdit != value)
                {
                    mAllowEdit = value;
                    OnAllowEditChanged();
                }
            }
        }

        protected virtual void OnUseTabBackgroundChanged()
        {

        }


    }
}
